<html>
<head><meta charset="utf-8"><title>perf issues · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html">perf issues</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195590564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195590564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195590564">(Apr 28 2020 at 16:33)</a>:</h4>
<p>I have an example where <code>textDocument/references</code> is taking about a minute with rust-analyzer pegged at 100% CPU , whereas IntelliJ "Find Usages" takes low single-digit seconds on the same piece of code. What is the best way to debug or report this issue?</p>



<a name="195591048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591048">(Apr 28 2020 at 16:37)</a>:</h4>
<p>Does this only happen only on the first request(s), or every time?</p>



<a name="195591140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591140">(Apr 28 2020 at 16:37)</a>:</h4>
<p>first request.</p>



<a name="195591198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591198">(Apr 28 2020 at 16:38)</a>:</h4>
<p>(It is also the first request in IntelliJ)</p>



<a name="195591388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591388">(Apr 28 2020 at 16:39)</a>:</h4>
<p>See <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1650" title="https://github.com/rust-analyzer/rust-analyzer/issues/1650">https://github.com/rust-analyzer/rust-analyzer/issues/1650</a> for the backstory. There's no persistence support, so the server has to analyze the whole project. <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4133" title="https://github.com/rust-analyzer/rust-analyzer/pull/4133">https://github.com/rust-analyzer/rust-analyzer/pull/4133</a> should have helped a little.</p>



<a name="195591557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591557">(Apr 28 2020 at 16:40)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu Nicola</span> It doesn't seem like persistence would account for the difference. In IntelliJ I invalidated the cache before trying, so I don't think it was benefiting from persistence.</p>



<a name="195591685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591685">(Apr 28 2020 at 16:41)</a>:</h4>
<p>I am using master from git, updated and built today, so I should already have <a href="https://github.com/rust-lang/rust/issues/4133" title="https://github.com/rust-lang/rust/issues/4133">#4133</a> applied.</p>



<a name="195591815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195591815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195591815">(Apr 28 2020 at 16:42)</a>:</h4>
<p>Ah, okay, then we're just slower. <a href="https://github.com/rust-lang/rust/issues/4133" title="https://github.com/rust-lang/rust/issues/4133">#4133</a> just hides the problem under the rug by pre-computing more things when you load a project, but doesn't help if you do the test immediately.</p>



<a name="195592066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592066">(Apr 28 2020 at 16:44)</a>:</h4>
<p>yes, also, I waited until the initial CPU spike from <code>rust-analyzer</code> ended before trying. So it should have been done building whatever indices it does on startup. BTW, this is about find references, not jump to definition.</p>



<a name="195592082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592082">(Apr 28 2020 at 16:44)</a>:</h4>
<p>For high-level profiling, maybe see <a href="https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/dev#profiling" title="https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/dev#profiling">https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/dev#profiling</a>. Generally, code profilers that work with C also work with Rust, but it might help to bump up the debug info level in <code>Cargo.toml</code>. I was looking at a profile <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4186#issuecomment-620576892" title="https://github.com/rust-analyzer/rust-analyzer/issues/4186#issuecomment-620576892">earlier today</a>, most of it seems to be trait solving.</p>



<a name="195592258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592258">(Apr 28 2020 at 16:45)</a>:</h4>
<p>How large is your project?</p>



<a name="195592265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592265">(Apr 28 2020 at 16:45)</a>:</h4>
<p>According to <code>perf</code>, the time is spent in <code>chalk_solve::recursive::Solver&lt;I&gt;::solve_goal</code></p>



<a name="195592457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592457">(Apr 28 2020 at 16:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232844">Brennan Vincent</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/perf.20issues/near/195592265" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/perf.20issues/near/195592265">said</a>:</p>
<blockquote>
<p>According to <code>perf</code>, the time is spent in <code>chalk_solve::recursive::Solver&lt;I&gt;::solve_goal</code></p>
</blockquote>
<p>Yup, trait solving</p>



<a name="195592663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195592663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195592663">(Apr 28 2020 at 16:48)</a>:</h4>
<p>The repo is <a href="https://github.com/MaterializeInc/materialize" title="https://github.com/MaterializeInc/materialize">https://github.com/MaterializeInc/materialize</a></p>
<div class="codehilite"><pre><span></span><code>~/c/materialize ❯❯❯ find src -name &#39;*.rs&#39; | xargs wc -l | grep total
  92434 total
</code></pre></div>


<p>So, 92kloc including whitespace. I've also added differnetial-dataflow to my workspace which is ~15kloc</p>



<a name="195593033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195593033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195593033">(Apr 28 2020 at 16:51)</a>:</h4>
<p>the code is somewhat heavy on traits/generics.</p>



<a name="195593561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195593561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195593561">(Apr 28 2020 at 16:54)</a>:</h4>
<p>What symbol are you using calling find all references on? I tried with a random one <code>pgwire::Codec::encode_error_notice_response</code> and it finished instantly, but that was a poor choice.</p>



<a name="195593668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195593668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195593668">(Apr 28 2020 at 16:55)</a>:</h4>
<p><code>pub struct Context</code> in <code>src/dataflow/render/context.rs</code></p>



<a name="195593900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195593900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195593900">(Apr 28 2020 at 16:56)</a>:</h4>
<p>Oh, yeah, that's slow</p>



<a name="195594200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195594200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195594200">(Apr 28 2020 at 16:58)</a>:</h4>
<p>Yeah, to be clear, <code>rust-analyzer</code> is mostly working fine on this codebase.</p>



<a name="195594679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195594679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195594679">(Apr 28 2020 at 17:01)</a>:</h4>
<p>I'm not sure how actionable this is today. <code>chalk</code> is still mostly unoptimized, and we don't have a way to extract a <code>chalk</code> input from a Rust project. <span class="user-mention" data-user-id="129457">@Florian Diebold</span> might chime in, though.</p>



<a name="195594858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195594858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195594858">(Apr 28 2020 at 17:02)</a>:</h4>
<p>Thanks for looking anyway. I was wondering if there is anything simple I could do to help like provide logs, etc., but it sounds like you were able to repro.</p>



<a name="195594999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195594999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195594999">(Apr 28 2020 at 17:03)</a>:</h4>
<p>last time I tried rust-analyzer was summer 2019; I gave up and switched to IntelliJ. But this time around it seems much more usable :) So congrats on all the hard work / progress, despite these random minor issues.</p>



<a name="195595009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195595009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195595009">(Apr 28 2020 at 17:03)</a>:</h4>
<p>I think we already have a couple of recent issues for "chalk is slow", but it wouldn't hurt if youfiled one.</p>



<a name="195595188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195595188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195595188">(Apr 28 2020 at 17:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="203546">Laurențiu Nicola</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/perf.20issues/near/195594679" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/perf.20issues/near/195594679">said</a>:</p>
<blockquote>
<p>I'm not sure how actionable this is today. <code>chalk</code> is still mostly unoptimized, and we don't have a way to extract a <code>chalk</code> input from a Rust project. <span class="user-mention silent" data-user-id="129457">Florian Diebold</span> might chime in, though.</p>
</blockquote>
<p>That is being worked on :)</p>



<a name="195595301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195595301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195595301">(Apr 28 2020 at 17:05)</a>:</h4>
<p>Specific data about Chalk performance is helpful</p>



<a name="195596571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195596571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195596571">(Apr 28 2020 at 17:14)</a>:</h4>
<p>Issue filed: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4194" title="https://github.com/rust-analyzer/rust-analyzer/issues/4194">https://github.com/rust-analyzer/rust-analyzer/issues/4194</a></p>



<a name="195597203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195597203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195597203">(Apr 28 2020 at 17:18)</a>:</h4>
<p><code>render::build_dataflow</code>, <code>render::render_join</code> and friends also take a lot of time to analyze</p>



<a name="195599848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195599848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195599848">(Apr 28 2020 at 17:37)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu Nicola</span> Those are some pretty complicated functions, so it doesn't surprise me. Did you find that out by looking at some profiling data? Or just by clicking around random stuff and trying it out</p>



<a name="195599908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/perf%20issues/near/195599908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/perf.20issues.html#195599908">(Apr 28 2020 at 17:37)</a>:</h4>
<p>Ran <code>rust-analyzer analysis-stats</code> and eyeballed it spending 30-60 seconds on those</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>